package com.factors.HuangHePing.Teacher_Quality;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class TeacherQualityDriver {

    public static void main(String[] args) throws Exception {

        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf, "Teacher Quality Score Avg");

        job.setJarByClass(TeacherQualityDriver.class);

        job.setMapperClass(TeacherQualityMapper.class);
        job.setReducerClass(TeacherQualityReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(DoubleWritable.class);

        FileInputFormat.addInputPath(job, new Path("Data/part-m-00000"));
        FileOutputFormat.setOutputPath(job, new Path("output/Huang/Teacher_Quality"));

        //判断输出路径是否存在 如果存在删除
        FileSystem fs = FileSystem.get(conf);
        if(fs.exists(new Path("output/Huang/Teacher_Quality"))){
            fs.delete(new Path("output/Huang/Teacher_Quality"),true);
        }
        // 提交作业并等待执行完成
        boolean resultFlag = job.waitForCompletion(true);
        //程序退出
        System.exit(resultFlag ? 0 :1);
    }
}